package com.xurui.kotlindelegate

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.xurui.kotlindelegate.databinding.FragmentOrderDetailBinding
import com.xurui.kotlindelegate.delegate.viewBinding

/**
 * <p>
 * Created by pengxr on 7/5/2021
 */
class OrderDetailFragment : Fragment(R.layout.fragment_order_detail) {
    private val binding by viewBinding(FragmentOrderDetailBinding::bind)

    override fun onViewCreated(root: View, savedInstanceState: Bundle?) {
        arguments?.run {
            val orderId = this.getInt(ARG_ORDER_ID)
            val orderType = this.getInt(ARG_ORDER_TYPE)
            // Display Value
            binding.tvDisplay.text = "orderId = $orderId, orderType = $orderType"
        }
    }

    companion object {
        private const val ARG_ORDER_ID = "orderId"
        private const val ARG_ORDER_TYPE = "orderType"

        fun get(orderId: Int, orderType: Int?): OrderDetailFragment {
            val fragment = OrderDetailFragment()
            val args = fragment.arguments ?: Bundle()
            args.putInt(ARG_ORDER_ID, orderId)
            args.putInt(ARG_ORDER_TYPE, orderType ?: 2)
            fragment.arguments = args
            return fragment
        }
    }
}